package com.hepinghospital.user.ui.activity.userinfo;

import android.widget.EditText;
import android.widget.TextView;

import com.hepinghospital.user.R;
import com.hepinghospital.user.base.BaseActivity;
import com.hepinghospital.user.util.ToastUtil;
import com.rest.business.RestProxy;
import com.rest.observer.BaseObserver;

import butterknife.BindView;
import butterknife.OnClick;
import jz.joyoung.robot.util.AES128;
import jz.joyoung.robot.util.UtilString;


/**
 * @Description: 修改密码
 * @Author: lzp
 * @CreateDate: 2023/3/23 14:49
 * @UpdateRemark: 更新说明
 */
public class UpdatePasswordActivity extends BaseActivity {
    @BindView(R.id.edt_password)
    EditText edt_password;
    @BindView(R.id.edt_newPassword)
    EditText edt_newPassword;
    @BindView(R.id.edt_newPassword2)
    EditText edt_newPassword2;
    @BindView(R.id.tv_title)
    TextView tvTitle;

    @Override
    protected void initViews() {
        tvTitle.setText("修改密码");
    }

    @Override
    protected void initData() {

    }

    @OnClick(R.id.btn_save)
    void btn_save() {
        updatePassword();
    }

    @Override
    protected int getLayoutResource() {
        return R.layout.activity_update_password;
    }


    private void updatePassword() {
        String oldPass = edt_password.getText().toString().trim();

        String newPassOne = edt_newPassword.getText().toString().trim();
        String newPassOneTwo = edt_newPassword2.getText().toString().trim();

        if (UtilString.isEmpty(oldPass)) {
            ToastUtil.showToast(mContext, "旧密码不能为空");
            return;
        }

        if (UtilString.isEmpty(newPassOne)) {
            ToastUtil.showToast(mContext, "新密码不能为空");
            return;
        }
        if (!newPassOne.equals(newPassOneTwo)) {
            ToastUtil.showToast(mContext, "两次输入密码不一致");
            return;
        }

        try {
            RestProxy.getInstance().updatePassword(AES128.encryptStringAES(edt_password.getText().toString(), "7t3e506jaa10xbd4"), AES128.encryptStringAES(edt_newPassword.getText().toString(), "7t3e506jaa10xbd4"), new BaseObserver<String>() {

                @Override
                public void onError(Throwable e) {
                    ToastUtil.onError(UpdatePasswordActivity.this, e);
                }

                @Override
                public void onSuccess(String result) {
                    ToastUtil.showToast(mContext, "操作成功");
                    finish();
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
